<?php

class Application_Form_MapaProcesos extends Sgit_Form
{
    
    public function init_form()
    {
        
         $request = Zend_Controller_Front::getInstance()->getRequest();
         $auth    = Zend_Auth::getInstance()->getIdentity();

         
         $file[1] = Sgit_Util_FileUpload::run('mapa-procesos','files');
         if(!file_exists($file[1]['dir'])) mkdir($file[1]['dir']);
         
         
         $id=$request->getParam('id');
         
        

         $ref=new Zend_Form_Element_Text('nombre');
         $ref ->setLabel('Nombre')
                ->setRequired(true)
                ->addFilter('StringTrim')
                ->addValidator('StringLength', false,array(0, 200));
         $this->addElement($ref);     
          
          
         $proyecto=new Zend_Form_Element_Text('revision');
         $proyecto->setLabel('Revisión')
                ->setRequired(true)
                ->addFilter('StringTrim')
                ->addValidator('StringLength', false,array(0, 10));
         $this->addElement($proyecto);    


        
         $files[0]=new Zend_Form_Element_File($file[1]['name']);
         $files[0]->setLabel('Adjunto')
                ->setDestination($file[1]['dir'])
                ->addValidator('Size', false, 31457280)
                ->setValueDisabled(true); 
         $this->addElement($files[0]);


        if($id){
             $options=Sgit_Util_GetFiles::run($file[1]['tabla'],$file[1]['key'],$id);
             
             if($options){
                 $files_lista1 = new Zend_Form_Element_MultiCheckbox($file[1]['activo']);
                 $files_lista1->setMultiOptions($options)
                    ->setLabel('Borrar Adjunto')
                    ->setAttrib('size',25); 
                 $this->addElement($files_lista1);
             }
         }


            
         $notas=new Zend_Form_Element_Textarea('notas');
         $notas->setLabel('Notas')
                ->setAttribs(array('rows'=>3,'cols'=>60))
                ->addFilter('StringTrim');
         $this->addElement($notas);    
            

      

  
       $this->setElementDecorators(array(
		    'ViewHelper',
		   'Errors',
		    array(array('data' => 'HtmlTag'),	array('tag' => 'td', 'class' => 'element')   ),
		    array('Label', array('tag' => 'td')),
		    array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
	   ));
       
       
 
          //fix file 
       $files[0]->setDecorators(
            array(
                'File',
                'Errors',
                array(array('data' => 'HtmlTag'), array('tag' => 'td','class' => 'element')),
                array('Label', array('tag' => 'td')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
            )
        );
    



    }
}
